package configx

import (
	"gitee.com/zhongguo168a/gocodes/datax/dictx"
	"gitee.com/zhongguo168a/gocodes/datax/treex"
)

func NewConfigDict() (obj *ConfigDict) {
	obj = &ConfigDict{}
	obj.IDictionary = dictx.New[string, *ConfigTreeItem]()
	return
}

type ConfigDict struct {
	dictx.IDictionary[string, *ConfigTreeItem]
}

func (set *ConfigDict) GetBy编号(编号 string) *ConfigTreeItem {
	val, _ := set.Get(编号)
	return val
}

func (set *ConfigDict) Filter默认的() {
	set.IDictionary = set.Filter(func(key string, val *ConfigTreeItem) bool {
		return val.M默认 == false
	}, nil)
}
func resetIndexTree(dict *ConfigDict) *treex.TreeRoot {
	var list []*treex.TreeListItem
	list = append(list, &treex.TreeListItem{
		Id: "/",
	})

	items := dict.Items()
	for i := 0; i < len(items); i++ {
		item := items[i]
		if item.F父编号 != "" {
			list = append(list, &treex.TreeListItem{
				Id: item.B编号, Parent: item.F父编号, Data: item,
			})
		} else {
			list = append(list, &treex.TreeListItem{
				Id: item.B编号, Parent: "/", Data: item,
			})
		}
	}
	return treex.NewByList(list)
}
